﻿Public Class fGame

#Region "Start/Stop Game Engine"

    Private Sub fGame_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        e.Cancel = True
        Globals.bEnding = True

    End Sub

#End Region

#Region "Keyboard Handling"

    Private Sub fGame_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If Globals.bDebugMode Then

            If e.KeyCode = Keys.Up Then
                Globals.DEBUG_Y(Globals.DEBUG_IDX) -= 1
                Globals.RefreshDebugXY()
            ElseIf e.KeyCode = Keys.Down Then
                Globals.DEBUG_Y(Globals.DEBUG_IDX) += 1
                Globals.RefreshDebugXY()
            ElseIf e.KeyCode = Keys.Left Then
                Globals.DEBUG_X(Globals.DEBUG_IDX) -= 1
                Globals.RefreshDebugXY()
            ElseIf e.KeyCode = Keys.Right Then
                Globals.DEBUG_X(Globals.DEBUG_IDX) += 1
                Globals.RefreshDebugXY()
            ElseIf e.KeyCode = Keys.Add Then
                If (Globals.DEBUG_IDX < 9) Then
                    Globals.DEBUG_IDX += 1
                    Globals.RefreshDebugXY()
                End If
            ElseIf e.KeyCode = Keys.Subtract Then
                If (Globals.DEBUG_IDX > 0) Then
                    Globals.DEBUG_IDX -= 1
                    Globals.RefreshDebugXY()
                End If
            ElseIf e.KeyCode = Keys.Tab Then
                Globals.DEBUG_SHOWTEXT = Not Globals.DEBUG_SHOWTEXT
            End If

        End If

        Keyboard.Input(Keyboard.KeyboardInputType.KeyDown, e)


    End Sub

    Private Sub fGame_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

        Keyboard.Input(Keyboard.KeyboardInputType.KeyUp, e)

    End Sub

    Private Sub fGame_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        Keyboard.Input(Keyboard.KeyboardInputType.KeyPress, e)

    End Sub

#End Region

#Region "Mouse Handling"

    Private Sub fGame_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

        Mouse.Input(Mouse.MouseInputType.MouseClick, e)

    End Sub

    Private Sub fGame_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDoubleClick

        Mouse.Input(Mouse.MouseInputType.MouseDoubleClick, e)

    End Sub

    Private Sub fGame_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

        Mouse.Input(Mouse.MouseInputType.MouseDown, e)

    End Sub

    Private Sub fGame_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

        Mouse.Input(Mouse.MouseInputType.MouseMove, e)

    End Sub

    Private Sub fGame_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

        Mouse.Input(Mouse.MouseInputType.MouseUp, e)

    End Sub

    Private Sub fGame_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus

        Mouse.LostFocus()

    End Sub

#End Region

#Region "Form Centring"

    Private Sub fGame_ClientSizeChanged(sender As Object, e As System.EventArgs) Handles Me.ClientSizeChanged
        If DirectX.Windowed And Not Me.WindowState = FormWindowState.Minimized Then
            Me.SetDesktopLocation(Screen.PrimaryScreen.WorkingArea.Left + (Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2), _
                                        Screen.PrimaryScreen.WorkingArea.Top + (Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))
        End If
    End Sub

#End Region

    Private Sub fGame_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.Text &= " - Client Version: " & EvoLib.Protocol.sClientVersion

    End Sub
End Class